package printParse.excel.jxlExcel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
 * 对Excel读写
 * @author Administrator
 *
 */
public class QueryExcelWrite {

	public static void main(String[] args) throws BiffException, IOException {

		File file = new File("D://test.xls");
		InputStream in = new FileInputStream(file);
		Workbook workbook = Workbook.getWorkbook(file);
		Sheet[] sheets = workbook.getSheets();
		if (sheets == null) {
			return;
		}
		for (int i = 0; i < sheets.length; i++) {
			Sheet sheet = sheets[i];
			int rows = sheet.getRows();
			int cols = sheet.getColumns();
			System.out.println("sheetName = " + sheet.getName());
			System.out.println("rows = " + rows);
			System.out.println("cols = " + cols);
			for (int j = 0; j < rows; j++) {
				for (int k = 0; k < cols; k++) {
					Cell cell = (Cell) sheet.getCell(k, j);//获得单元格
					System.out.print(cell.getContents() + "\t");//读取单元格
				}
				System.out.println();
			}
			System.out.println("------------------------------------");
		}

	}

}
